/*
 *  @ProductName@
 *  Copyright (C) @CopyrightYear@
 *    National Institute of Advanced Industrial Science and Technology (AIST)
 *    Registration Number: @AISTRegistrationNumber@
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package jp.go.aist.six.vuln.core.scap.cpe.dictionary;

import jp.go.aist.six.util.castor.CastorDataStore;
import jp.go.aist.six.vuln.model.scap.cpe.dictionary.ComponentTree;
import jp.go.aist.six.vuln.model.scap.cpe.dictionary.CpeItem;
import jp.go.aist.six.vuln.model.scap.cpe.dictionary.CpeList;
import jp.go.aist.six.vuln.model.scap.cpe.dictionary.VendorComponent;
import java.util.ArrayList;
import java.util.Collection;



/**
 * A CPE Dictionary data store.
 *
 * @author  Akihito Nakamura, AIST
 * @version $Id: CpeDictionaryStore.java 256 2010-06-14 03:58:05Z nakamura5akihito $
 */
public class CpeDictionaryStore
extends CastorDataStore
{

//    /**
//     * Logger.
//     */
//    private static Log  _LOG = LogFactory.getLog( NvdStore.class );



    /**
     * Constructor.
     */
    public CpeDictionaryStore()
    {
    }



//    /**
//     *
//     */
//    public CpeItem findItemByCpeName(
//                    final String cpename
//                    )
//    {
//        List<CpeItem>  objects = find( CpeItem.class,
//                        RelationalBinding.equalBinding( "name", cpename ), null, null );
//
//        return (objects.size() > 0 ? objects.get( 0 ) : null);
//    }
//
//
//
//    /**
//     */
//    public List<CpeItem> searchItem(
//                    final SearchCriteria criteria
//                    )
//    {
//        return search( CpeItem.class, criteria );
//    }
//
//
//
//    /**
//     */
//    public int countItem(
//                    final Binding filter
//                    )
//    {
//        return count( CpeItem.class, filter );
//    }



    /**
     */
    public Object createList(
                    final CpeList list
                    )
    {
        Collection<CpeItem>  item_list = list.getItem();
        if (item_list != null  &&  item_list.size() > 0) {
            Collection<CpeItem>  p_item_list = new ArrayList<CpeItem>();
            for (CpeItem  item : item_list) {
                CpeItem  p_item = sync( CpeItem.class, item );
                p_item_list.add( p_item );
            }
            list.setItem( p_item_list );
        }

        ComponentTree  tree = list.getComponentTree();
        if (tree != null  &&  tree.getVendor().size() > 0) {
            Collection<VendorComponent>  p_vendor_list = new ArrayList<VendorComponent>();
            for (VendorComponent  vendor : tree.getVendor()) {
                VendorComponent  p_vendor = sync( VendorComponent.class, vendor );
                p_vendor_list.add( p_vendor );
            }
            tree.setVendor( p_vendor_list );
        }

        return create( CpeList.class, list );
    }



//    /**
//     */
//    public String createItem(
//                    final CpeItem item
//                    )
//    {
//        return create( CpeItem.class, item );
//    }
//
//
//    /**
//     */
//    public CpeItem syncItem(
//                    final CpeItem item
//                    )
//    {
//        return sync( CpeItem.class, item );
//    }

}
// CpeDictionaryStore
